import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, forwardRef, useImperativeHandle, } from "react";
import AntToolTip from "~/public/cpas-ui/components-ui/ant-components/AntToolTip";
import CpasIcon from "~/public/cpas-ui/components-ui/components/Icon";
import SelectBox from "devextreme-react/select-box";
import { message } from "antd";
// 行编辑
const RowEditor = forwardRef((props, ref) => {
    const { _this, rowTagToolItemRef, rowTagPolymericRef, rowCustomOperationRef, } = props;
    useImperativeHandle(ref, () => ({
        focus: test,
    }));
    const test = () => {
        console.log("test");
    };
    useEffect(() => {
        // console.log('RowEditor 更新了 _this.tagInputRef:', _this.tagInputRef);
        // const aaa = document.getElementById("rowTagInputId");
        // console.log('aaa', aaa);
    });
    //声明整理模式下移动行的函数
    //批量移动时遵循一个原则，当队头触顶或者队伍触底则整体不移动
    const handleMoveRow = (direction) => {
        const ranges = _this.gridRef.state.currentRange;
        if (!ranges) {
            _this.showErrorNotify("请选择行进行操作");
            return;
        }
        const movesRow = []; //需要移动的行
        const afterMoveRange = []; //需要划选的单元格范围
        for (let i = 0; i < ranges.length; i++) {
            const range = ranges[i];
            const { computedMovesRows, computedAfterMoveRange } = _this.gridRef.gridService.getMoveRows(range, direction);
            //如果有计算结果则进行移动数组填充
            if (computedMovesRows.length > 0 && computedAfterMoveRange.length > 0) {
                movesRow.push(...computedMovesRows);
                afterMoveRange.push(computedAfterMoveRange);
            }
        }
        //调用移动行服务
        _this.gridService.moveRowsByDirection(movesRow, direction);
        if (afterMoveRange.length > 0) {
            //调用移动后的划选
            _this.hot.selectCells(afterMoveRange);
        }
        _this.gridRef.setTableContentChange(true, {
            type: "行移动",
            params: { movesRow, direction },
        });
    };
    const closeCalculateTag = async () => {
        console.log("删除行运算标签");
        await _this.setRowOperatorType("del");
        _this.rowOperatorChange();
    };
    //行运算
    const handleCalculateTag = async () => {
        const ranges = _this.gridRef.state.currentRange;
        if (!ranges) {
            _this.showErrorNotify("请选择行进行操作");
            return;
        }
        const { row } = _this.gridRef.state.currentRecord.coords;
        const rowCount = _this.hot.countRows();
        console.log(ranges, "ranges", row, rowCount);
        if (!ranges || row !== rowCount - 1) {
            _this.showErrorNotify("请选择最后一行行进行操作");
            return;
        }
        await _this.setRowOperatorType("set");
        _this.rowOperatorChange();
    };
    return (_jsxs("div", { className: "col col3", children: [_jsx("div", { className: "row row1", children: _jsx("span", { children: "\u884C\u7F16\u8F91" }) }), _jsxs("div", { className: "tools-item-last-container", children: [_jsxs("div", { className: "row row2", children: [_jsx(AntToolTip, { placement: "bottom", title: "\u884C\u6807\u7B7E", children: _jsx("div", { className: "tools-item", onClick: () => {
                                        _this.rowEditorService.openSetTag("row");
                                    }, id: "labelPanel", ref: rowTagToolItemRef, children: _jsx(CpasIcon, { type: "icon-hangbiaoqian", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u884C\u6807\u7B7E\u805A\u5408", children: _jsx("div", { className: "tools-item", onClick: () => {
                                        _this.rowEditorService.openSetTag("row", true);
                                        _this.openPolyMeric("row");
                                    }, id: "labelJuhePanel", ref: rowTagPolymericRef, children: _jsx(CpasIcon, { type: "icon-hangbiaoqianjuhe", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u51CF", children: _jsx("div", { className: _this.state.weightType === "j"
                                        ? "tools-item cpas-menu-item-active"
                                        : "tools-item", onClick: () => {
                                        _this.setWeight("row", "j");
                                    }, children: _jsx(CpasIcon, { type: "icon-jian", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u5176\u4E2D", children: _jsx("div", { className: _this.state.weightType === "z"
                                        ? "tools-item cpas-menu-item-active"
                                        : "tools-item", onClick: () => {
                                        _this.setWeight("row", "z");
                                    }, children: _jsx(CpasIcon, { type: "icon-zhong", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u81EA\u5B9A\u4E49\u53C2\u4E0E\u8FD0\u7B97", children: _jsx("div", { className: "tools-item", ref: rowCustomOperationRef, onClick: () => {
                                        _this.openCustomOperation();
                                    }, children: _jsx(CpasIcon, { type: "icon-a-bianzu19", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u884C\u805A\u5408\u8C41\u514D\u5217", children: _jsx("div", { className: _this.state.pExclude === true
                                        ? "tools-item cpas-menu-item-active"
                                        : "tools-item", onClick: () => {
                                        _this.setPolymericExclude("row", "p");
                                    }, children: _jsx(CpasIcon, { type: "icon-hangjuhehuomianlie1", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u884C\u805A\u5408\u4E0D\u53C2\u4E0E\u5217", children: _jsx("div", { className: _this.state.cExclude === true
                                        ? "tools-item cpas-menu-item-active"
                                        : "tools-item", onClick: () => {
                                        _this.setPolymericExclude("row", "c");
                                    }, children: _jsx(CpasIcon, { type: "icon-hangjuhefangshijihangshuxing", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u884C\u4E0A\u79FB", children: _jsx("div", { className: "tools-item", onClick: () => {
                                        handleMoveRow("top");
                                    }, children: _jsx(CpasIcon, { type: "icon-arrow-up", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u884C\u4E0B\u79FB", children: _jsx("div", { className: "tools-item", onClick: () => {
                                        handleMoveRow("bottom");
                                    }, children: _jsx(CpasIcon, { type: "icon-arrow-down", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: _this.state.isRowOperatorTag ? "取消行运算" : "行运算", children: _jsx("div", { className: _this.state.isRowOperatorTag
                                        ? "tools-item cpas-menu-item-active"
                                        : "tools-item", onClick: () => {
                                        if (_this.state.isRowOperatorTag) {
                                            //删除行运算标签
                                            closeCalculateTag();
                                        }
                                        else {
                                            //打行运算标签
                                            handleCalculateTag();
                                        }
                                    }, children: _jsx(CpasIcon, { type: "icon-zhongxinjisuan", className: "cpas-icon" }) }) })] }), _jsxs("div", { className: "row row3", children: [_jsx("div", { className: "tools-item-inline", children: _jsx("span", { className: "row-aggregation-text", children: "\u884C\u805A\u5408" }) }), _jsx("div", { className: "tools-item-width-auto", children: _jsx(SelectBox, { style: { minWidth: 180 }, 
                                    //disabled={true}
                                    placeholder: "请选择", displayExpr: "name", valueExpr: "id", value: _this.state.rowPType, onItemClick: async (e) => {
                                        const pType = e.itemData.id;
                                        const coords = _this.gridRef.state.currentRecord.coords;
                                        const rowIndex = coords && coords.row ? coords.row : 1;
                                        //const colIndex = coords && coords.col ? coords.col : 1;
                                        if (pType === "CLEAR") {
                                            await _this.selectRowColumnTagsChange("row");
                                            await _this.juiheRowChange(e);
                                        }
                                        else {
                                            const tagName = `TOP--${parseInt(String(10000 * Math.random())) + ""}`;
                                            if (+rowIndex < 2) {
                                                return message.error("操作行聚合运算的单元格位置不对");
                                            }
                                            await _this.juiheRowChange(e);
                                            await _this.setTag("row", tagName, "top");
                                            await _this.setRowCountType(pType, [tagName], "top");
                                        }
                                        return _this.gridRef.setTableContentChange(true, {
                                            type: "行聚合",
                                            params: {
                                                value: _this.state.rowPType,
                                            },
                                        });
                                        //_this.columnEditorService.rowAggregationChange(e)
                                    }, items: _this.rowAggregationOption, className: "select-box-style-min" }) })] })] })] }));
});
export default RowEditor;
